<template>
  <view class="bd t1">
    <view style="text-align: center" v-if="!list.length">暂无数据</view>
    <view class="s-list">
      <view
        class="s-item"
        v-for="(v, index) in list"
        :key="index"
        @tap="goDetail(v)"
      >
        <view style="font-size: 34upx; font-weight: 900; padding: 10upx 0">{{
          v.title
        }}</view>
        <image
          :src="v.imgUrl"
          mode="scaleToFill"
          style="width: 100%; height: 400upx"
        ></image>
        <view class="flex flex-j-b">
          <view style="color: #19c7e1">查看详情</view>
          <view
            class="iconfont iconarrow-right"
            style="font-size: 40upx; color: #c3c3c3"
          ></view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      page: {},
      list: [],
    };
  },
  onReachBottom() {
    //console.log('触底了')
    if (this.page.isLastPage) return;
    this.getInjectPlanMore(this.page.pageNum + 1);
  },
  onReady() {
    // this.getUiStyle();
  },
  methods: {
    getUiStyle() {
      var style = plus.navigator.getUiStyle();
      if ("dark" == style) {
        console.log("当前为暗黑模式");
        uni.setTabBarStyle({
          backgroundColor: "#1B1C1E",
        });
        uni.setNavigationBarColor({
          frontColor: "#ffffff",
          backgroundColor: "#1B1C1E",
          animation: {
            duration: 400,
            timingFunc: "easeIn",
          },
        });
      } else {
        console.log("当前为普通模式");
      }
    },
    // 获取接种计划
    getInjectPlan(pageNumber) {
      let self = this;
      uni.showLoading({ title: "加载中", mask: true });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      this.config
        .get("/proposal/getList", {
          pageNum: pageNumber ? pageNumber : 1,
          pageSize: "10",
        })
        .then((res) => {
          console.log(res);
          uni.hideLoading();
          if (res.data.code === 200) {
            self.page = res.data.data;
            self.list = res.data.data.list || [];
          } else {
            if (res.data.code == "-201") {
              self.config.handleError(res.data);
            } else {
              uni.showToast({
                title: self.config.handleError(res.data),
                icon: "none",
              });
            }
          }
        });
    },
    getInjectPlanMore(pageNumber) {
      let self = this;
      uni.showLoading({ title: "加载中", mask: true });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      this.config
        .get("/proposal/getList", {
          pageNum: pageNumber ? pageNumber : 1,
          pageSize: "10",
        })
        .then((res) => {
          uni.hideLoading();
          if (res.data.code === 200) {
            self.page = res.data.data;
            self.list = self.list.concat(res.data.data.list);
          } else {
            if (res.data.code == "-201") {
              self.config.handleError(res.data);
            } else {
              uni.showToast({
                title: self.config.handleError(res.data),
                icon: "none",
              });
            }
          }
        });
    },
    // 详情
    goDetail(v) {
      uni.navigateTo({
        url:
          "/pages/main/child/backlog/suggest-detail?id=" +
          v.id +
          "&title=" +
          v.title,
      });
    },
  },
  mounted() {
    this.getInjectPlan();
  },
};
</script>

<style lang="less" scoped>
.s-list {
  padding: 30upx;
  .s-item {
    margin: 0 0 30upx;
  }
}
</style>
<style scoped>
@media (prefers-color-scheme: closedark) {
  .bd {
    background-color: #1b1c1e !important;
  }
  .t1 {
    color: #ccc !important;
  }
}
</style>